package jnzb.model.queue;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import jnzb.misc.StorageUnit;
import jnzb.model.nzb.NZB;

public class FinishedTableModel extends AbstractTableModel {

	private ArrayList<NZBFinishedEvent> finished = new ArrayList<NZBFinishedEvent>();

	private String[] columns = new String[] { "Time", "Size", "NZB Name" };

	public FinishedTableModel() {
	}

	@Override
	public String getColumnName(int column) {
		return columns[column];
	}

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount() {
		return finished==null?0:finished.size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		String value;
		switch (col) {
		case 0:
			value = finished.get(row).getTime();
			break;
		case 1:
			long valuel = finished.get(row).getSize();
			value=StorageUnit.of(valuel).format(valuel);
			break;
		case 2:
			value = finished.get(row).getNzbName();
			break;
		default:
			value = null;
		}
		return value;
	}

	/**
	 * Will record the finish details of the nzb
	 * @param nzb
	 */
	public void nzbFinished(NZB nzb) {
		NZBFinishedEvent nfe = new NZBFinishedEvent(nzb.getFilename(), nzb.getSize());
		this.finished.add(nfe);
		this.fireTableDataChanged();
	}

}
